/**
 * created by lht 2008-9-18
 */

package com.hollycrm.ahunicom.sheet.maintenance.logic;

import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import org.springframework.orm.hibernate.HibernateTemplate;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;

public class EventListLogic extends HibernateDaoSupport implements Util{
	
    private Session ss=null;

   public int getCount()
   {
       HibernateTemplate ht = getHibernateTemplate();
       SessionFactory sessionFactory = ht.getSessionFactory();

     try {
       ss = sessionFactory.openSession();
       //Query q = ht.createQuery(ss, "select count(a) from TblSheetEventParameter a ");
       Query q = ss.createQuery("select count(a) from TblSheetEventParameter a ");
       int rows= ((Integer) q.iterate().next()).intValue();
       ss.flush();
       return rows;
     } catch (HibernateException ex) {
        ex.printStackTrace();
     }finally{
    		if(ss!=null){
    			try {
					ss.close();
				} catch (HibernateException e) {
					e.printStackTrace();
				}
    		}
     }
     return 0;

   }

   public List  getList(int pagesize,int currow) {
 	  List list = null;
      HibernateTemplate ht = getHibernateTemplate();
      SessionFactory sessionFactory = ht.getSessionFactory();
      try {
          ss = sessionFactory.openSession();
          Query q=ss.createQuery("from TblSheetEventParameter");
          q.setFirstResult(currow);
          q.setMaxResults(pagesize);
          list=q.list();
          ss.flush();
          return list;
        } catch (HibernateException ex) {
        	ex.printStackTrace();
        }finally{
       		if(ss!=null){
       			try {
   					ss.close();
   				} catch (HibernateException e) {
   					e.printStackTrace();
   				}
       		}
        }
	 return null;
   }

}
